package com.authorization.project.authorization.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.authorization.project.authorization.mapper.AuthorizationMoudleMappingMapper;
import com.authorization.project.authorization.domain.AuthorizationMoudleMapping;
import com.authorization.project.authorization.service.IAuthorizationMoudleMappingService;

/**
 * 授权信息-模块中间Service业务层处理
 * 
 * @author 李晓雷
 * @date 2020-04-27
 */
@Service
public class AuthorizationMoudleMappingServiceImpl implements IAuthorizationMoudleMappingService 
{
    @Autowired
    private AuthorizationMoudleMappingMapper authorizationMoudleMappingMapper;

    /**
     * 查询授权信息-模块中间
     * 
     * @param id 授权信息-模块中间ID
     * @return 授权信息-模块中间
     */
    @Override
    public AuthorizationMoudleMapping selectAuthorizationMoudleMappingById(Long id)
    {
        return authorizationMoudleMappingMapper.selectAuthorizationMoudleMappingById(id);
    }

    /**
     * 查询授权信息-模块中间列表
     * 
     * @param authorizationMoudleMapping 授权信息-模块中间
     * @return 授权信息-模块中间
     */
    @Override
    public List<AuthorizationMoudleMapping> selectAuthorizationMoudleMappingList(AuthorizationMoudleMapping authorizationMoudleMapping)
    {
        return authorizationMoudleMappingMapper.selectAuthorizationMoudleMappingList(authorizationMoudleMapping);
    }

    /**
     * 新增授权信息-模块中间
     * 
     * @param authorizationMoudleMapping 授权信息-模块中间
     * @return 结果
     */
    @Override
    public int insertAuthorizationMoudleMapping(AuthorizationMoudleMapping authorizationMoudleMapping)
    {
        return authorizationMoudleMappingMapper.insertAuthorizationMoudleMapping(authorizationMoudleMapping);
    }

    /**
     * 修改授权信息-模块中间
     * 
     * @param authorizationMoudleMapping 授权信息-模块中间
     * @return 结果
     */
    @Override
    public int updateAuthorizationMoudleMapping(AuthorizationMoudleMapping authorizationMoudleMapping)
    {
        return authorizationMoudleMappingMapper.updateAuthorizationMoudleMapping(authorizationMoudleMapping);
    }

    /**
     * 批量删除授权信息-模块中间
     * 
     * @param ids 需要删除的授权信息-模块中间ID
     * @return 结果
     */
    @Override
    public int deleteAuthorizationMoudleMappingByIds(Long[] ids)
    {
        return authorizationMoudleMappingMapper.deleteAuthorizationMoudleMappingByIds(ids);
    }

    /**
     * 删除授权信息-模块中间信息
     * 
     * @param id 授权信息-模块中间ID
     * @return 结果
     */
    @Override
    public int deleteAuthorizationMoudleMappingById(Long id)
    {
        return authorizationMoudleMappingMapper.deleteAuthorizationMoudleMappingById(id);
    }

    /**
     * 批量添加
     * @param userid
     * @param moduleArray
     */
    @Override
    public void batchInsertAuthorizationMoudleMapping(String userid, List<Long> moduleArray, Long packageId) {
        moduleArray.stream().forEach(moduleId ->{
            AuthorizationMoudleMapping authorizationMoudleMapping = new AuthorizationMoudleMapping();
            authorizationMoudleMapping.setModuleId(moduleId);
            authorizationMoudleMapping.setUserid(userid);
            authorizationMoudleMapping.setPackageId(packageId);
            this.insertAuthorizationMoudleMapping(authorizationMoudleMapping);
        });
    }

    /**
     * 根据客户编号查询模块ID集合
     * @param userid
     * @return
     */
    @Override
    public List<Long> selectMoudleIdsByUserId(String userid, Long productId) {
        return authorizationMoudleMappingMapper.selectMoudleIdsByUserId(userid, productId);
    }

    /**
     * 根据客户编号删除信息
     * @param userid
     */
    @Override
    public void deleteAuthorizationMoudleMappingByUserId(String userid) {
        authorizationMoudleMappingMapper.deleteAuthorizationMoudleMappingByUserId(userid);
    }

    /**
     * 查询客户选择的套餐
     * @param userid
     * @return
     */
    @Override
    public Long selectCheckedPackageIdByUserId(String userid, Long productId) {
        return authorizationMoudleMappingMapper.selectCheckedPackageIdByUserId(userid, productId);
    }


}
